package ytmc;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 *
 * @author Kicok
 */
public class FileUtils
{
    private static Pattern extensionPattern;
    static
    {
        extensionPattern = Pattern.compile( "\\.([^.\\\\/]+)$" );
    }

    public static String getExtension( File file )
    {
        return getExtension( file.getName() );
    }

    public static String getExtension( String filePath )
    {
        Matcher m = extensionPattern.matcher( filePath );
        if( m.find() )
        {
            return m.group( 1 );
        }

        return "";
    }


    /**
     * @return File path without extension
     */
    public static String getFileName( File file )
    {
        return getFileName( file.getAbsolutePath() );
    }

    /**
     * @return File path without extension
     */
    public static String getFileName( String filePath )
    {
        return filePath.replaceFirst( extensionPattern.pattern(), "" );
    }
}